package net.wantongtech.xa.uploadbasicinfo.dao;

import com.wtkj.dao.impl.BaseDataTemplate;
import com.wtkj.dao.impl.GenericResultSetExtractor;
import com.wtkj.vo.dzzf.base.xxjh.MessageSend;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 导出邮储批量扣款数据DAO实现
 *
 * @author MaShibo
 * 2020/12/10 0010
 */
@Repository
public class ExportPSBCBatchDeductionDao extends BaseDataTemplate {

    public Integer queryExportDataNum() {
        final String sql =
                "SELECT COUNT(1)\n" +
                        "  FROM ETC_MESSAGESEND A\n" +
                        " WHERE A.CHANNELTYPE = 'PSBC'\n" +
                        "   AND A.SENDTIME < TRUNC(SYSDATE)";
        return jdbcTemplate.queryForObject(sql, Integer.class);
    }


    public List<MessageSend> queryExportMsgSendByRowNum(int start, int end) {
        final String sql =
                "SELECT *\n" +
                        "  FROM (SELECT A.MSGID, A.MSGBODY, A.COUNT, A.AMOUNT, ROWNUM AS RM\n" +
                        "          FROM ETC_MESSAGESEND A\n" +
                        "         WHERE A.CHANNELTYPE = 'PSBC'\n" +
                        "           AND A.SENDTIME < TRUNC(SYSDATE)\n" +
                        "         ORDER BY A.MSGID DESC)\n" +
                        " WHERE RM >= ?\n" +
                        "   AND RM <= ?";
        return jdbcTemplate.query(sql, GenericResultSetExtractor.getInstance(MessageSend.class), start, end);
    }
}
